<?php

class Manage extends Controller {
	
	function Manage()
	{
		parent::Controller();	
	}
	
	function index()
	{
		$this->load->helper('form');
		$this->load->model('Manage_Model');

		$data['title'] = "GCMS >> Pages";
		$data['heading'] = "Pages";
		$data['style'] = base_url().'system/application/views/content.css';
		
		$data['header'] = $this->load->view('header', $data, true);
		$data['footer'] = $this->load->view('footer', $data, true);
		$this->_login_check($data, 'manage_view');

	}
	
	function create()
	{
		$this->load->helper('form');
		$this->load->database();

		$data['title'] = "GCMS >> Pages >> Write";
		$data['heading'] = "Pages >> Write";
		$data['style'] = base_url().'system/application/views/content.css';
		
		$data['header'] = $this->load->view('header', $data, true);
		$data['footer'] = $this->load->view('footer', $data, true);
        $this->_login_check($data, 'manage_write_view');
	}
	
	function create2()
	{
		$this->load->model('Manage_Model');
		
		$this->Manage_Model->insert_entry();
		redirect('/manage', 'refresh');
	}
	
	function edit()
	{
		$this->load->helper('form');
		$this->load->helper('date');
		$this->load->database();

		$data['title'] = "GCMS >> Pages >> Edit";
		$data['heading'] = "Pages >> Edit";
		$data['id'] = $this->uri->segment(3);
		$data['style'] = base_url().'system/application/views/content.css';
		
		$data['header'] = $this->load->view('header', $data, true);
		$data['footer'] = $this->load->view('footer', $data, true);
        $this->_login_check($data, 'manage_edit_view');
	}
	
	function edit2()
	{
		$this->load->model('Manage_Model');

		$this->Manage_Model->update_entry();
		redirect('/manage', 'refresh');
	}
	
	function delete()
	{
		$this->load->model('Manage_Model');

		$this->Manage_Model->delete_entry($this->uri->segment(3));
		redirect('/manage', 'refresh');
	}
	
	function _login_check($data, $dest)
	{
		$this->load->library('session');
		$this->load->library('validation');
		$logged_in = $this->session->userdata('logged_in');
		if(!$logged_in){
			$this->load->view('login', $data);
		} else {
			$this->load->view($dest, $data);
		}
	}
	
}
?>